home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!besu223.LOCAL
- From: Dave Easley <easleydp@ncp.gpt.co.uk>
- Newsgroups: comp.lang.c++
- Subject: Simple 8-bit integer class not so simple?
- Date: Fri, 9 Feb 1996 14:32:25 +0000
- Message-ID: <9602091432.AA11113@besu223.LOCAL>
- X-NNTP-Posting-Host: besu223.LOCAL
- Content-Length: 1883
- X-Mail2News-Path: net.gpt.co.uk!cvhp99!besf227!besu223.LOCAL
-
- On our project's utilities library provides portable integer types
- UtInt8 (8 bit signed integer), UtUint8 (unsigned), UtInt16, etc.
-
- No prizes for guesing that the 8 bit ones are typedef'd to signed and
- unsigned char. Problem is, some of the users have (understandably)
- complained that when they cout one of these, it prints as a char
- rather than an integer.
-
- So we are going to move to classes for UtInt8 and UtUint8 so we can
- tweak the ostream& operator<<(ostream& s, UtInt8 val) behaviour (and
- operator>>). All the other behaviour was fine, but once we start using
- a class we understand we have to supply all the relational and
- arithmatic operators as well.
-
- I can see we'll definetly need to provide operator ++ and --. Also all
- the standard binary relational and arithmatic ops for the simple case
- where it's a UtInt8 on both sides. But I'm unsure what the best
- approach is to ensure that expressions where these types are mixed
- with other numeric types work as one would expect, e.g.
- [int] < [UtInt8]
- [UtInt8] < [unsigned]
- [UtInt8] * [float]
- etc. (many permutations!)
-
- Does anyone know the best way to do this? If we just provide a type
- conversion operator to int will this do? I can imagine not because
- (considering the [UtInt8] * [float] example) the compiler won't do
- more than one implicit type conversion.
- If we provide type conv ops for all the fundamental numeric types,
- won't this lead to ambiguities in certain cases?
-
- TIA for any advice,
-
- Dave Easley
-
- --
- GPT Ltd is not responsible for my opinions.
- ***********************************************************
- * Dave Easley * GPT Wisecom Systems *
- * easleydp@ncp.gpt.co.uk * Technology Drive *
- * Tel: +44 (0) 115 9433348 * Nottingham, UK *
- * Fax: +44 (0) 115 9433805 * NG9 1LA *
- ***********************************************************
-